package cn.com.cetccst.compliancecheck.checker;

import android.content.Context;
import android.content.res.Resources;
import android.os.Build;

import java.util.ArrayList;
import java.util.List;

import cn.com.cetccst.compliancecheck.R;
import cn.com.cetccst.tools.log.CommonLogger;

public class OSVersionChecker extends Checker {
    private final List<String> versions;
    private static OSVersionChecker instance;

    private OSVersionChecker(Context context) {
        super(CheckerType.OSVersion);
        name = context.getString(R.string.compliance_OS);
        versions = new ArrayList<>();
    }

    public static void init(Context context) {
        if(instance == null) {
            instance = new OSVersionChecker(context);
        }
    }

    public static OSVersionChecker getInstance() {
        return instance;
    }
    @Override
    public void check(Context context) {
        String curVersion = Build.VERSION.RELEASE;
        CommonLogger.info("Start check OS version:" + curVersion);
        super.check(context);
        if(!isEnable())
            return;
        List<String> osVersions = getVersions();
        if (osVersions.isEmpty()) {
            setResult(CheckResult.Pass);
        }
        for (String version : osVersions) {
            if (version.equals(curVersion)) {
                setResult(CheckResult.Pass);
            }
        }
        setResult(CheckResult.Violated);
    }

    public List<String> getVersions() {
        return versions;
    }

    public void setVersions(List<String> models) {
        this.versions.clear();
        this.versions.addAll(models);
    }

}
